<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Released under the MIT License.
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------

namespace app\ball\controller;

use cmf\controller\HomeBaseController;
use think\Db;

class BallController extends HomeBaseController
{
    public function index()
    {
        $request = input('request.');
        $num = $this->request->param('num',0);

        if($num != 0)
        {
            $where = ['blue' => $num];
        }
        else
        {
            $where = [];
        }

        $data = Db::name('ball')->where($where)->order('id desc')->paginate(200);
        $group = Db::name('ball')
                ->field('blue,count(blue) as count')
                ->order('count desc')
                ->group('blue')
                ->select()
                ->toArray();
        // 获取分页显示
        $data->appends($request);//保持分页中的查询条件
        $page = $data->render();
        $this->assign('data', $data);
        $this->assign('page', $page);
        $this->assign('num',$num);
        $this->assign('group',$group);
        return $this->fetch(':index');
    }

    public function add()
    {
        return $this->fetch(':add');
    }

    public function addpost()
    {
        $request = input('request.');
        unset($request['s']);
        $status = Db::name('ball')->insert($request,false,true);
        $this->success("添加成功！", url("Ball/index"));
    }

    public function ws()
    {
        return $this->fetch(':ws');
    }
}
